package com.guoshengdeu.door.controller;


import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.guoshengdeu.door.entity.ConfigBannerPic;
import com.guoshengdeu.door.service.IConfigBannerPicService;
import com.guoshengdeu.door.util.RespResult;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author yfly
 * @since 2021-06-01
 */
@Api("Banner图片")
@RestController
@RequestMapping("/config-bannerpic")
public class ConfigBannerPicController {

    @Autowired
    private IConfigBannerPicService bannerPicService;

    //查询bannerPic
    @ApiOperation("查询")
    @RequestMapping("list")
    public List<ConfigBannerPic> queryBanner(){
        return bannerPicService.list();
    }

    //添加更新
    @ApiOperation("添加更新")
    @RequestMapping("addbannerpic")
    public RespResult addBannerPic(@RequestBody ConfigBannerPic bannerPic){
        boolean saveOrUpdate = bannerPicService.saveOrUpdate(bannerPic);
        if (saveOrUpdate){
            return RespResult.success();
        }
        return RespResult.error("添加或更新失败");
    }

    //删除bannerPic
    @ApiOperation("删除")
    @DeleteMapping("delebannerpic")
    public RespResult delebannerPic(int id){
        boolean removeById = bannerPicService.removeById(id);
        if (removeById){
            return RespResult.success();
        }
        return RespResult.error("删除失败");
    }

    //分页
    @ApiOperation("分页")
    @GetMapping("page")
    public RespResult page(Page<ConfigBannerPic> page){
        Page<ConfigBannerPic> pages = bannerPicService.page(page);
        return RespResult.success(pages);
    }
}
